<%@ page import="com.alipay.api.AlipayClient" %>
<%@ page import="com.touzi.alipay.AliCons" %>
<%@ page import="com.alipay.api.request.AlipayTradeQueryRequest" %>
<%@ page import="com.alipay.api.response.AlipayTradeQueryResponse" %>
<%@ page import="com.touzi.utils.BeanUtils" %>
<%@ page import="com.alipay.api.request.AlipayFundTransOrderQueryRequest" %>
<%@ page import="com.alipay.api.response.AlipayFundTransOrderQueryResponse" %>
<%@ page import="com.alipay.api.DefaultAlipayClient" %>
<%@ page import="com.touzi.proconfig.AliConfig" %>
<%@ page import="com.touzi.constants.DbCons" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.touzi.mapper.SysconfigMapper" %><%--
  Created by IntelliJ IDEA.
  User: w7851
  Date: 2018/5/24
  Time: 10:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    SqlSession sqlSession = ((SqlSessionFactory) application.getAttribute(DbCons.DB_FACTORY)).openSession();
    SysconfigMapper sysconfigMapper = sqlSession.getMapper(SysconfigMapper.class);
    String appid = sysconfigMapper.findConfBykey("APPID");
    String app_private_key = sysconfigMapper.findConfBykey("APP_PRIVATE_KEY");
    String alipay_public_key = sysconfigMapper.findConfBykey("ALIPAY_PUBLIC_KEY");
    String ali_noty = sysconfigMapper.findConfBykey("ALI_NOTY");
    sqlSession.close();

    AlipayClient alipayClient = new DefaultAlipayClient(AliConfig.ALI_URL,
            appid, app_private_key, AliConfig.PARA_TYPE,
            AliConfig.CHARSET, alipay_public_key, AliConfig.SIGNTYPE);

    String type = request.getParameter("type");
    String outtradeno = request.getParameter("out_no");
    String result = "";

    if (type.equals("buyorder")) {
        AlipayTradeQueryRequest alipayTradeQueryRequest = new AlipayTradeQueryRequest();
        alipayTradeQueryRequest.setBizContent("{" +
                "\"out_trade_no\":\"" + outtradeno + "\"" +
                "  }");
        AlipayTradeQueryResponse alipayTradeQueryResponse = alipayClient.execute(alipayTradeQueryRequest);
        if (alipayTradeQueryResponse.isSuccess()) {
            result = BeanUtils.serializeBeanGentle(alipayTradeQueryResponse);
        } else {
            result = "验证错误verify wrong!!!!";
        }
    } else if (type.equals("transorder")) {

        AlipayFundTransOrderQueryRequest alipayFundTransOrderQueryRequest = new AlipayFundTransOrderQueryRequest();
        alipayFundTransOrderQueryRequest.setBizContent("{" +
                "\"out_biz_no\":\"" + outtradeno + "\"" +
                "  }");
        AlipayFundTransOrderQueryResponse alipayFundTransOrderQueryResponse = alipayClient.execute(alipayFundTransOrderQueryRequest);
        if (alipayFundTransOrderQueryResponse.isSuccess()) {
            result = BeanUtils.serializeBeanGentle(alipayFundTransOrderQueryResponse);
        } else {
            result = "验证错误verify wrong!!!!";
        }
    } else {
        result = " 参数错误!!!!";
    }

%>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <style>
        #content {
            width: 400px;
            padding: 16px;
            margin: auto;
        }
    </style>
</head>
<body>
<div id="content">
 <pre>
     <%=result%>
 </pre>
</div>
</body>
</html>
